import axios from "axios";

const request = axios.create({
  baseURL: "http://127.0.0.1:8081",
});

export default {
  namespaced: true,
  state: {
    title: "shop",
  },
  getters: {
    g1: () => "shop g1",
  },
  mutations: {
    SET_TITLE: (state, value) => (state.title = value),
  },
  actions: {
    add(store, { x, y }) {
      console.log(store.state.title, store.rootState, x + y);
    },
  },
  modules: {
    shopA: {
      namespaced: true,
      state: {
        title: "shopA",
        users: [],
      },
      getters: {
        g1: () => "shopA g1",
      },
      mutations: {
        SET_TITLE: (state, value) => (state.title = value),
        SET_USERS: (state, value) => (state.users = value),
      },
      actions: {
        add(store, { x, y }) {
          console.log(store.state.title, store.rootState, x + y);
        },
        async getUsers(store) {
          const { data } = await request.get("/users");
          store.commit("SET_USERS", data);
        },
      },
    },
  },
};
